﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HepsiBuradaXml
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();

            Response.ContentType = "text/xml";
            Response.Write(xmlGenerate());
            Response.End();
        }

        string xmlGenerate()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<?xml version=\"1.0\" standalone=\"yes\"?>");
            sb.AppendLine("<Urunler>");
            using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["db"].ConnectionString))
            {
                cn.Open();
                using (SqlCommand cmd = new SqlCommand(ConfigurationManager.AppSettings["sql"], cn))
                {
                    SqlDataReader rd = cmd.ExecuteReader();
                    while (rd.Read())
                    {
                        sb.AppendLine("  <Urun>");
                        sb.AppendFormat("    <KategoriAdi>{0}</KategoriAdi>\r\n", rd.ReadString("kategori"));
                        sb.AppendFormat("    <UrunID>{0}</UrunID>\r\n", rd.ReadString("id"));
                        sb.AppendFormat("    <UrunAdi>{0}</UrunAdi>\r\n", rd.ReadString("adi"));
                        sb.AppendFormat("    <KDV>{0}</KDV>\r\n", rd.ReadString("kdv"));
                        sb.AppendFormat("    <OzelFiyat>{0}</OzelFiyat>\r\n", rd.ReadString("ozelfiyat"));
                        sb.AppendFormat("    <ListeFiyat>{0}</ListeFiyat>\r\n", rd.ReadString("listefiyat"));
                        sb.AppendFormat("    <Kur>{0}</Kur>\r\n", rd.ReadString("doviz"));
                        sb.AppendFormat("    <Barcode>{0}</Barcode>\r\n", rd.ReadString("barkod"));
                        sb.AppendFormat("    <StokAdedi>{0}</StokAdedi>\r\n", rd.ReadString("eldeki"));
                        sb.AppendFormat("    <ImageName1>{0}.jpg</ImageName1>\r\n", rd.ReadString("resim"));
                        sb.AppendLine("  </Urun>");
                    }
                }
                cn.Close();
            }
            sb.AppendLine("</Urunler>");
            return sb.ToString();
        }
    }
}